package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.business.entities.regmin.States;
import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="DOCUMENT", schema="MPC")
public class Document implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3572635024715216531L;

	@Id
	@Column(insertable=false, updatable=false, nullable=false)
	private Integer id;
	
	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@ManyToOne
	@JoinColumn(name="DOC_CLASSIFICATION_ID")
	private AppList docClassfication;
	
	@ManyToOne
	@JoinColumn(name="DOCUMENT_TYPE_ID")
	private AppList documentType;
	
	@Column(name="DOCUMENT_NO")
	private String documentNo;
	
	@ManyToOne
	@JoinColumn(name="CODE_STATE")
	private States states;
	
	@Temporal(TemporalType.DATE)
	@Column(name="DATE_ISSUED")
	private Date dateIssued;
	
	@Temporal(TemporalType.DATE)
	@Column(name="EXP_DATE")
	private Date expDate;
	
	@Column(name="SEQUENCE_DOC")
	private boolean sequenceDoc;
	
	@Column(name="START_SEQUENCE", length=30)
	private String startSequence;
	
	@Column(name="END_SEQUENCE", length=30)
	private String endSequence;
	
	@Column(name="DOC_TOTAL_NO")
	private Integer docTotalNo;
	
	@Column(length=500)
	private String notes;

	
	
	public Document() {
		// TODO Auto-generated constructor stub
	
	}	
	public Document(Document document) {
		this.dateIssued = document.getDateIssued();
		this.docClassfication = document.getDocClassfication();
		this.documentNo = document.getDocumentNo();
		this.documentType = document.getDocumentType();
		this.expDate = document.getExpDate();
		this.notes = document.getNotes();
		this.states = document.getStates();
	
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public AppList getDocClassfication() {
		return docClassfication;
	}

	public void setDocClassfication(AppList docClassfication) {
		this.docClassfication = docClassfication;
	}

	public AppList getDocumentType() {
		return documentType;
	}

	public void setDocumentType(AppList documentType) {
		this.documentType = documentType;
	}

	public String getDocumentNo() {
		return documentNo;
	}

	public void setDocumentNo(String documentNo) {
		this.documentNo = documentNo;
	}

	public States getStates() {
		return states;
	}

	public void setStates(States states) {
		this.states = states;
	}

	public Date getDateIssued() {
		return dateIssued;
	}

	public void setDateIssued(Date dateIssued) {
		this.dateIssued = dateIssued;
	}

	public Date getExpDate() {
		return expDate;
	}

	public void setExpDate(Date expDate) {
		this.expDate = expDate;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}




	
	@Override
	public String toString() {
		
		if(documentNo != null){
			if(docClassfication != null){
				if(documentType != null){
					return documentNo + ", " + documentType.getTag() + ", " + docClassfication.getTag();
				}
				else return documentNo + ", " + docClassfication.getTag();
			}
			else return documentNo;
		}
		
		return "Dokumenti nr. " + id;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dateIssued == null) ? 0 : dateIssued.hashCode());
		result = prime
				* result
				+ ((docClassfication == null) ? 0 : docClassfication.hashCode());
		result = prime * result
				+ ((documentNo == null) ? 0 : documentNo.hashCode());
		result = prime * result
				+ ((documentType == null) ? 0 : documentType.hashCode());
		result = prime * result + ((expDate == null) ? 0 : expDate.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((notes == null) ? 0 : notes.hashCode());
		result = prime * result + ((states == null) ? 0 : states.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (dateIssued == null) {
			if (other.dateIssued != null)
				return false;
		} else if (!dateIssued.equals(other.dateIssued))
			return false;
		if (docClassfication == null) {
			if (other.docClassfication != null)
				return false;
		} else if (!docClassfication.equals(other.docClassfication))
			return false;
		if (documentNo == null) {
			if (other.documentNo != null)
				return false;
		} else if (!documentNo.equals(other.documentNo))
			return false;
		if (documentType == null) {
			if (other.documentType != null)
				return false;
		} else if (!documentType.equals(other.documentType))
			return false;
		if (expDate == null) {
			if (other.expDate != null)
				return false;
		} else if (!expDate.equals(other.expDate))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (states == null) {
			if (other.states != null)
				return false;
		} else if (!states.equals(other.states))
			return false;
		return true;
	}
	
	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (dateIssued == null) {
			if (other.dateIssued != null)
				return false;
		} else if (!dateIssued.equals(other.dateIssued))
			return false;
		if (docClassfication == null) {
			if (other.docClassfication != null)
				return false;
		} else if (!docClassfication.equals(other.docClassfication))
			return false;
		if (documentNo == null) {
			if (other.documentNo != null)
				return false;
		} else if (!documentNo.equals(other.documentNo))
			return false;
		if (documentType == null) {
			if (other.documentType != null)
				return false;
		} else if (!documentType.equals(other.documentType))
			return false;
		if (expDate == null) {
			if (other.expDate != null)
				return false;
		} else if (!expDate.equals(other.expDate))
			return false;
		
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (states == null) {
			if (other.states != null)
				return false;
		} else if (!states.equals(other.states))
			return false;
		return true;
	}
	public boolean isSequenceDoc() {
		return sequenceDoc;
	}
	public void setSequenceDoc(boolean sequenceDoc) {
		this.sequenceDoc = sequenceDoc;
	}
	public String getStartSequence() {
		return startSequence;
	}
	public void setStartSequence(String startSequence) {
		this.startSequence = startSequence;
	}
	public String getEndSequence() {
		return endSequence;
	}
	public void setEndSequence(String endSequence) {
		this.endSequence = endSequence;
	}
	public Integer getDocTotalNo() {
		return docTotalNo;
	}
	public void setDocTotalNo(Integer docTotalNo) {
		this.docTotalNo = docTotalNo;
	}
	
	
	
}
